﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using GoblinXNA.Graphics.Geometry;
using GoblinXNA.SceneGraph;
using Microsoft.Xna.Framework;

namespace _3DAR
{
    class Cursor
    {
        private MarkerNode _groundMarkerNode;

        public MarkerNode CursorMarkerNode;
        public Vector3 PositionRelativeCamera
        {
            get
            {
                return this.CursorMarkerNode.WorldTransformation.Translation;//??
            }
        }

        public Vector3 PositionRelativeScene
        {
            get
            {
                Vector3 position =
                    (this.CursorMarkerNode.WorldTransformation *
                     (Matrix.Invert(this._groundMarkerNode.WorldTransformation))).Translation;
                return position;
            }
        }
    
        public Cursor(Scene scene, PrimitiveGeometryCreator primitiveGeometryCreator, MarkerNode groundMarkerNode)
        {
            this._groundMarkerNode = groundMarkerNode;
            CursorMarkerNode = new MarkerNode(scene.MarkerTracker, "cursor markers.xml");
            const float thickness = 0.2f;
            GeometryNode cursorZGeometryNode = primitiveGeometryCreator.Create(new TexturedBox(thickness, thickness, 10.0f), Color.Blue);
            GeometryNode cursorYGeometryNode = primitiveGeometryCreator.Create(new TexturedBox(thickness, 10.0f, thickness), Color.Green);
            GeometryNode cursorXGeometryNode = primitiveGeometryCreator.Create(new TexturedBox(10.0f, thickness, thickness), Color.Red);
            scene.RootNode.AddChild(CursorMarkerNode);
            CursorMarkerNode.AddChild(cursorXGeometryNode);
            CursorMarkerNode.AddChild(cursorYGeometryNode);
            CursorMarkerNode.AddChild(cursorZGeometryNode);
        }
    }
}
